/**
 * 
 */
package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.bean.WorkerBean;
import com.util.ConnectionGateway;

/**
 * @author Veer
 *
 */
public class WorkerDAO {
	
public static boolean addWorker(WorkerBean workerBean)
{   String emp_id = null;
	Connection connection = ConnectionGateway.connection;
	try {
        PreparedStatement obj = connection.prepareStatement("NEXT VALUE FOR employee_id");
        ResultSet rs = obj.executeQuery();
        if(rs.next()){
        	 emp_id = "EMP"+rs.getString(1);
        }
		PreparedStatement insertWorker = connection.prepareStatement("insert into Employee values (?,?,?,?,?,?)");
		insertWorker.setString(6,emp_id);
		insertWorker.setString(1, workerBean.getName());
		insertWorker.setString(2, workerBean.getJobTitle());
		insertWorker.setString(3, workerBean.getAddress());
		insertWorker.setString(4, workerBean.getPhone());
		insertWorker.setDate(5, workerBean.getHireDate());
		int rowsupdated = insertWorker.executeUpdate();
		connection.commit();
		if(rowsupdated!=0)
			return true;
		else
			return false;
		
	
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		System.out.println("SQL Insert Query Snapped ! ");
		return false;
	}
	finally{
		ConnectionGateway.DisConnect();
	}
}

}
